//
//  GenderViewController.m
//  Toyohu
//
//  Created by Heige on 16/4/20.
//  Copyright © 2016年 celia. All rights reserved.
//

#import "GenderViewController.h"
#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
@interface GenderViewController ()
{
    UISegmentedControl *seg;
}

@end

@implementation GenderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    seg = [[UISegmentedControl alloc] initWithItems:@[@"男",@"女"]];
    seg.frame = CGRectMake(0, 0, 200, 40);
    seg.center = CGPointMake(WIDTH / 2, HEIGHT / 4);
    [seg addTarget:self action:@selector(segChangeIndex) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:seg];
    
}

- (void) segChangeIndex{
    if (seg.selectedSegmentIndex == 0) {
        NSString *str = @"男";
        
        NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
        [userDef setObject:str forKey:@"sex"];
        [userDef synchronize];
        [self dismissViewControllerAnimated:YES completion:nil];
        
    }
    else{
        NSString *str = @"女";
        
        NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
        [userDef setObject:str forKey:@"sex"];
        [userDef synchronize];
        [self dismissViewControllerAnimated:YES completion:nil];
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
